package com.example.liwushuo.fragment;


import java.util.ArrayList;
import java.util.List;

import com.example.liwushuo.MoreInfoActivity;
import com.example.liwushuo.R;
import com.example.liwushuo.adapter.MyFmAdapter;
import com.example.liwushuo.bar.SelfBar;
import com.viewpagerindicator.TabPageIndicator;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author 这是我的信息的碎片
 */
public class MyInfoFragment extends Fragment implements OnClickListener {

	private TabPageIndicator tabPageIndicator;
	private ViewPager viewPager;
	private MyFmAdapter adapter;
	private List<Fragment> list;
	

	private TextView loginTv;
	private ImageView imageView, jiantouTv;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		View view = inflater.inflate(R.layout.self_fragment, null);
		loginTv = (TextView) view.findViewById(R.id.login_id);
		jiantouTv = (ImageView) view.findViewById(R.id.jiantou_id);
		imageView = (ImageView) view.findViewById(R.id.touxiang_id);
		loginTv.setOnClickListener(this);
		jiantouTv.setOnClickListener(this);
		imageView.setOnClickListener(this);
		getFragmentManager().beginTransaction()
				.replace(R.id.self_bar_id, new SelfBar()).commit();

		initView(view);
		//initData();
		return view;
	}

	//private void initData() {
		// TODO Auto-generated method stub
//		list.add(new GiftFragment());
//		list.add(new GongLueFragment());

//		adapter.notifyDataSetChanged();
//		tabPageIndicator.setViewPager(viewPager);
//	}

	private void initView(View view) {
		// TODO Auto-generated method stub
		 String titles[] = {"喜欢的礼物", "喜欢的攻略"};
		viewPager = (ViewPager) view.findViewById(R.id.like_viewPager);
		tabPageIndicator = (TabPageIndicator) view.findViewById(R.id.like_vpi);
		list = new ArrayList<Fragment>();
		list.add(new GiftFragment());
		list.add(new GongLueFragment());
		adapter = new MyFmAdapter(getChildFragmentManager(), list, titles);
		viewPager.setAdapter(adapter);

		tabPageIndicator.setViewPager(viewPager);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.login_id:
			Intent intent=new Intent(getActivity(), MoreInfoActivity.class);
			startActivity(intent);
			break;

		case R.id.jiantou_id:
			Intent intent1=new Intent(getActivity(), MoreInfoActivity.class);
			startActivity(intent1);
			break;
		case R.id.touxiang_id:
			Intent intent2=new Intent(getActivity(), MoreInfoActivity.class);
			startActivity(intent2);
			break;
		}
	}

}
